package com.sec.android.widgetapp.calculator;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.sec.android.app.calculator.R.styleable;

public class Panel extends LinearLayout
{
  private Animation.AnimationListener animationListener = new Animation.AnimationListener()
  {
    public void onAnimationEnd(Animation paramAnimation)
    {
      Panel.access$002(Panel.this, Panel.State.READY);
      if (Panel.this.mIsShrinking)
        Panel.this.mContent.setVisibility(8);
      Panel.this.postProcess();
    }

    public void onAnimationRepeat(Animation paramAnimation)
    {
    }

    public void onAnimationStart(Animation paramAnimation)
    {
      Panel.access$002(Panel.this, Panel.State.ANIMATING);
    }
  };
  View.OnClickListener clickListener = new View.OnClickListener()
  {
    public void onClick(View paramView)
    {
      if (Panel.this.mBringToFront)
        Panel.this.bringToFront();
      if (Panel.this.initChange())
        Panel.this.post(Panel.this.startAnimation);
    }
  };
  private boolean mAniEnd = true;
  private boolean mBringToFront;
  private Drawable mClosedHandle;
  private View mContent;
  private int mContentHeight;
  private int mContentId;
  private int mContentWidth;
  private int mDuration;
  private GestureDetector mGestureDetector;
  private PanelOnGestureListener mGestureListener;
  private View mHandle;
  private int mHandleId;
  private Interpolator mInterpolator;
  private boolean mIsShrinking;
  private boolean mLinearFlying;
  private Drawable mOpenedHandle;
  private int mOrientation;
  private int mPosition;
  private State mState;
  private boolean mTouchable = true;
  private float mTrackX;
  private float mTrackY;
  private float mVelocity;
  private float mWeight;
  private OnPanelListener panelListener;
  Runnable startAnimation = new Runnable()
  {
    public void run()
    {
      int i = 0;
      int j = 0;
      int m = 0;
      int n = 0;
      int i5;
      int i6;
      label67: int i4;
      label122: boolean bool2;
      label185: label205: int i3;
      if (Panel.this.mState == Panel.State.FLYING)
      {
        Panel localPanel3 = Panel.this;
        if ((Panel.this.mPosition == 0) || (Panel.this.mPosition == 2))
        {
          i5 = 1;
          if (Panel.this.mVelocity <= 0.0F)
            break label323;
          i6 = 1;
          Panel.access$1102(localPanel3, i5 ^ i6);
        }
      }
      else
      {
        if (Panel.this.mOrientation != 1)
          break label419;
        i4 = Panel.this.mContentHeight;
        if (Panel.this.mIsShrinking)
          break label335;
        if (Panel.this.mPosition != 0)
          break label329;
        m = -i4;
        if (Panel.this.mState != Panel.State.TRACKING)
          break label366;
        if (Math.abs(Panel.this.mTrackY - m) < Math.abs(Panel.this.mTrackY - n))
        {
          Panel localPanel2 = Panel.this;
          if (Panel.this.mIsShrinking)
            break label360;
          bool2 = true;
          Panel.access$1102(localPanel2, bool2);
          n = m;
        }
        m = (int)Panel.this.mTrackY;
        if ((Panel.this.mState != Panel.State.FLYING) || (!Panel.this.mLinearFlying))
          break label391;
        i3 = Math.max((int)(1000.0F * Math.abs((n - m) / Panel.this.mVelocity)), 20);
      }
      label323: label329: label335: int i1;
      label360: label366: int k;
      while (true)
      {
        Panel.access$1602(Panel.this, Panel.access$1302(Panel.this, 0.0F));
        if (i3 != 0)
          break label674;
        Panel.access$002(Panel.this, Panel.State.READY);
        if (Panel.this.mIsShrinking)
          Panel.this.mContent.setVisibility(8);
        Panel.this.postProcess();
        return;
        i5 = 0;
        break;
        i6 = 0;
        break label67;
        m = i4;
        break label122;
        if (Panel.this.mPosition == 0);
        for (i1 = -i4; ; i1 = i4)
          break;
        bool2 = false;
        break label185;
        if (Panel.this.mState != Panel.State.FLYING)
          break label205;
        m = (int)Panel.this.mTrackY;
        break label205;
        label391: i3 = Panel.this.mDuration * Math.abs(i1 - m) / Panel.this.mContentHeight;
        continue;
        label419: int i2 = Panel.this.mContentWidth;
        label453: boolean bool1;
        if (!Panel.this.mIsShrinking)
          if (Panel.this.mPosition == 2)
          {
            i = -i2;
            if (Panel.this.mState != Panel.State.TRACKING)
              break label622;
            if (Math.abs(Panel.this.mTrackX - i) < Math.abs(Panel.this.mTrackX - j))
            {
              Panel localPanel1 = Panel.this;
              if (Panel.this.mIsShrinking)
                break label616;
              bool1 = true;
              label515: Panel.access$1102(localPanel1, bool1);
              j = i;
            }
            i = (int)Panel.this.mTrackX;
          }
        while (true)
        {
          if ((Panel.this.mState != Panel.State.FLYING) || (!Panel.this.mLinearFlying))
            break label647;
          i3 = Math.max((int)(1000.0F * Math.abs((j - i) / Panel.this.mVelocity)), 20);
          break;
          i = i2;
          break label453;
          if (Panel.this.mPosition == 2);
          for (k = -i2; ; k = i2)
            break;
          label616: bool1 = false;
          break label515;
          label622: if (Panel.this.mState != Panel.State.FLYING)
            continue;
          i = (int)Panel.this.mTrackX;
        }
        label647: i3 = Panel.this.mDuration * Math.abs(k - i) / Panel.this.mContentWidth;
      }
      label674: TranslateAnimation localTranslateAnimation = new TranslateAnimation(i, k, m, i1);
      localTranslateAnimation.setDuration(i3);
      localTranslateAnimation.setAnimationListener(Panel.this.animationListener);
      if ((Panel.this.mState == Panel.State.FLYING) && (Panel.this.mLinearFlying))
        localTranslateAnimation.setInterpolator(new LinearInterpolator());
      while (true)
      {
        Panel.this.startAnimation(localTranslateAnimation);
        break;
        if (Panel.this.mInterpolator == null)
          continue;
        localTranslateAnimation.setInterpolator(Panel.this.mInterpolator);
      }
    }
  };
  View.OnTouchListener touchListener = new View.OnTouchListener()
  {
    int initX;
    int initY;
    boolean setInitialPosition;

    public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
    {
      int j;
      if (Panel.this.mState == Panel.State.ANIMATING)
        j = 0;
      while (true)
      {
        return j;
        int i = paramMotionEvent.getAction();
        int m;
        if (i == 0)
        {
          Panel.access$102(Panel.this, Panel.this.panelListener.onPanelClicked(Panel.this));
          if (!Panel.this.mTouchable)
          {
            j = 1;
            continue;
          }
          if (Panel.this.mBringToFront)
            Panel.this.bringToFront();
          this.initX = 0;
          this.initY = 0;
          if (Panel.this.mContent.getVisibility() == 8)
          {
            if (Panel.this.mOrientation != 1)
              break label182;
            if (Panel.this.mPosition == 0)
            {
              m = -1;
              label135: this.initY = m;
            }
          }
          else
          {
            this.setInitialPosition = true;
          }
        }
        while (true)
        {
          if (Panel.this.mGestureDetector.onTouchEvent(paramMotionEvent))
            break label345;
          if (Panel.this.mTouchable)
            break label325;
          j = 1;
          break;
          m = 1;
          break label135;
          label182: if (Panel.this.mPosition == 2);
          for (int k = -1; ; k = 1)
          {
            this.initX = k;
            break;
          }
          if (!Panel.this.mTouchable)
          {
            j = 1;
            break;
          }
          if (this.setInitialPosition)
          {
            this.initX *= Panel.this.mContentWidth;
            this.initY *= Panel.this.mContentHeight;
            Panel.this.mGestureListener.setScroll(this.initX, this.initY);
            this.setInitialPosition = false;
            this.initX = (-this.initX);
            this.initY = (-this.initY);
          }
          paramMotionEvent.offsetLocation(this.initX, this.initY);
        }
        label325: if (i == 1)
          Panel.this.post(Panel.this.startAnimation);
        label345: j = 0;
      }
    }
  };

  public Panel(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    TypedArray localTypedArray = paramContext.obtainStyledAttributes(paramAttributeSet, R.styleable.Panel);
    this.mDuration = localTypedArray.getInteger(0, 300);
    this.mPosition = localTypedArray.getInteger(1, 1);
    this.mLinearFlying = localTypedArray.getBoolean(4, false);
    this.mWeight = localTypedArray.getFraction(5, 0, 1, 0.0F);
    if ((this.mWeight < 0.0F) || (this.mWeight > 1.0F))
      this.mWeight = 0.0F;
    this.mOpenedHandle = localTypedArray.getDrawable(6);
    this.mClosedHandle = localTypedArray.getDrawable(7);
    IllegalArgumentException localIllegalArgumentException = null;
    this.mHandleId = localTypedArray.getResourceId(2, 0);
    if (this.mHandleId == 0)
      localIllegalArgumentException = new IllegalArgumentException(localTypedArray.getPositionDescription() + ": The handle attribute is required and must refer to a valid child.");
    this.mContentId = localTypedArray.getResourceId(3, 0);
    if (this.mContentId == 0)
      localIllegalArgumentException = new IllegalArgumentException(localTypedArray.getPositionDescription() + ": The content attribute is required and must refer to a valid child.");
    localTypedArray.recycle();
    if (localIllegalArgumentException != null)
      throw localIllegalArgumentException;
    if ((this.mPosition == 0) || (this.mPosition == 1));
    for (int i = 1; ; i = 0)
    {
      this.mOrientation = i;
      setOrientation(this.mOrientation);
      this.mState = State.READY;
      this.mGestureListener = new PanelOnGestureListener();
      this.mGestureDetector = new GestureDetector(this.mGestureListener);
      this.mGestureDetector.setIsLongpressEnabled(false);
      setBaselineAligned(false);
      return;
    }
  }

  private float ensureRange(float paramFloat, int paramInt1, int paramInt2)
  {
    return Math.min(Math.max(paramFloat, paramInt1), paramInt2);
  }

  private void postProcess()
  {
    if ((this.mIsShrinking) && (this.mClosedHandle != null))
      this.mHandle.setBackgroundDrawable(this.mClosedHandle);
    label78: label89: 
    while (true)
    {
      if (this.panelListener != null)
      {
        if (!this.mIsShrinking)
          break label78;
        this.panelListener.onPanelClosed(this);
      }
      while (true)
      {
        return;
        if ((this.mIsShrinking) || (this.mOpenedHandle == null))
          break label89;
        this.mHandle.setBackgroundDrawable(this.mOpenedHandle);
        break;
        this.panelListener.onPanelOpened(this);
      }
    }
  }

  protected void dispatchDraw(Canvas paramCanvas)
  {
    if ((this.mState == State.ABOUT_TO_ANIMATE) && (!this.mIsShrinking))
    {
      if (this.mOrientation != 1)
        break label101;
      int i = this.mContentHeight;
      if ((this.mPosition == 2) || (this.mPosition == 0))
        i = -i;
      if (this.mOrientation != 1)
        break label109;
      paramCanvas.translate(0.0F, i);
    }
    while (true)
    {
      if ((this.mState == State.TRACKING) || (this.mState == State.FLYING))
        paramCanvas.translate(this.mTrackX, this.mTrackY);
      super.dispatchDraw(paramCanvas);
      return;
      label101: int j = this.mContentWidth;
      break;
      label109: paramCanvas.translate(j, 0.0F);
    }
  }

  public Drawable getClosedHandle()
  {
    return this.mClosedHandle;
  }

  public View getContent()
  {
    return this.mContent;
  }

  public View getHandle()
  {
    return this.mHandle;
  }

  public boolean initChange()
  {
    int i;
    if (this.mState != State.READY)
    {
      i = 0;
      return i;
    }
    this.mState = State.ABOUT_TO_ANIMATE;
    if (this.mContent.getVisibility() == 0);
    for (boolean bool = true; ; bool = false)
    {
      this.mIsShrinking = bool;
      if (!this.mIsShrinking)
        this.mContent.setVisibility(0);
      i = 1;
      break;
    }
  }

  public boolean isOpen()
  {
    if (this.mContent.getVisibility() == 0);
    for (int i = 1; ; i = 0)
      return i;
  }

  protected void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    ViewParent localViewParent = getParent();
    if ((localViewParent != null) && ((localViewParent instanceof FrameLayout)))
      this.mBringToFront = true;
  }

  protected void onFinishInflate()
  {
    super.onFinishInflate();
    this.mHandle = findViewById(this.mHandleId);
    if (this.mHandle == null)
    {
      String str2 = getResources().getResourceEntryName(this.mHandleId);
      throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + str2 + "'");
    }
    this.mHandle.setOnTouchListener(this.touchListener);
    this.mHandle.setOnClickListener(this.clickListener);
    this.mContent = findViewById(this.mContentId);
    if (this.mContent == null)
    {
      String str1 = getResources().getResourceEntryName(this.mHandleId);
      throw new RuntimeException("Your Panel must have a child View whose id attribute is 'R.id." + str1 + "'");
    }
    removeView(this.mHandle);
    removeView(this.mContent);
    View localView1;
    if ((this.mPosition == 0) || (this.mPosition == 2))
    {
      localView1 = this.mContent;
      addView(localView1);
      if ((this.mPosition != 0) && (this.mPosition != 2))
        break label278;
    }
    label278: for (View localView2 = this.mHandle; ; localView2 = this.mContent)
    {
      addView(localView2);
      if (this.mOpenedHandle != null)
        this.mHandle.setBackgroundDrawable(this.mOpenedHandle);
      this.mContent.setClickable(true);
      this.mContent.setVisibility(0);
      if (this.mWeight > 0.0F)
        break label286;
      return;
      localView1 = this.mHandle;
      break;
    }
    label286: ViewGroup.LayoutParams localLayoutParams = this.mContent.getLayoutParams();
    if (this.mOrientation == 1)
      localLayoutParams.height = -1;
    while (true)
    {
      this.mContent.setLayoutParams(localLayoutParams);
      break;
      localLayoutParams.width = -1;
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    super.onLayout(paramBoolean, paramInt1, paramInt2, paramInt3, paramInt4);
    this.mContentWidth = this.mContent.getWidth();
    this.mContentHeight = this.mContent.getHeight();
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    View localView;
    if ((this.mWeight > 0.0F) && (this.mContent.getVisibility() == 0))
    {
      localView = (View)getParent();
      if (localView != null)
      {
        if (this.mOrientation != 1)
          break label64;
        paramInt2 = View.MeasureSpec.makeMeasureSpec((int)(localView.getHeight() * this.mWeight), 1073741824);
      }
    }
    while (true)
    {
      super.onMeasure(paramInt1, paramInt2);
      return;
      label64: paramInt1 = View.MeasureSpec.makeMeasureSpec((int)(localView.getWidth() * this.mWeight), 1073741824);
    }
  }

  public void setAniEnd(boolean paramBoolean)
  {
    this.mAniEnd = paramBoolean;
  }

  public void setOnPanelListener(OnPanelListener paramOnPanelListener)
  {
    this.panelListener = paramOnPanelListener;
  }

  class PanelOnGestureListener
    implements GestureDetector.OnGestureListener
  {
    float scrollX;
    float scrollY;

    PanelOnGestureListener()
    {
    }

    public boolean onDown(MotionEvent paramMotionEvent)
    {
      this.scrollY = 0.0F;
      this.scrollX = 0.0F;
      Panel.this.initChange();
      return true;
    }

    public boolean onFling(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)
    {
      Panel.access$002(Panel.this, Panel.State.FLYING);
      Panel localPanel = Panel.this;
      float f;
      if (Panel.this.mOrientation == 1)
        f = paramFloat2;
      while (true)
      {
        Panel.access$1202(localPanel, f);
        Panel.this.post(Panel.this.startAnimation);
        return true;
        f = paramFloat1;
      }
    }

    public void onLongPress(MotionEvent paramMotionEvent)
    {
    }

    public boolean onScroll(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)
    {
      Panel.access$002(Panel.this, Panel.State.TRACKING);
      float f1 = 0.0F;
      float f2 = 0.0F;
      if (Panel.this.mOrientation == 1)
      {
        this.scrollY -= paramFloat2;
        if (Panel.this.mPosition == 0)
          f1 = Panel.this.ensureRange(this.scrollY, -Panel.this.mContentHeight, 0);
      }
      while (true)
      {
        if ((f2 != Panel.this.mTrackX) || (f1 != Panel.this.mTrackY))
        {
          Panel.access$1602(Panel.this, f2);
          Panel.access$1302(Panel.this, f1);
          Panel.this.invalidate();
        }
        return true;
        f1 = Panel.this.ensureRange(this.scrollY, 0, Panel.this.mContentHeight);
        continue;
        this.scrollX -= paramFloat1;
        if (Panel.this.mPosition == 2)
        {
          f2 = Panel.this.ensureRange(this.scrollX, -Panel.this.mContentWidth, 0);
          continue;
        }
        f2 = Panel.this.ensureRange(this.scrollX, 0, Panel.this.mContentWidth);
      }
    }

    public void onShowPress(MotionEvent paramMotionEvent)
    {
    }

    public boolean onSingleTapUp(MotionEvent paramMotionEvent)
    {
      return false;
    }

    public void setScroll(int paramInt1, int paramInt2)
    {
      this.scrollX = paramInt1;
      this.scrollY = paramInt2;
    }
  }

  public static abstract interface OnPanelListener
  {
    public abstract boolean onPanelClicked(Panel paramPanel);

    public abstract void onPanelClosed(Panel paramPanel);

    public abstract void onPanelOpened(Panel paramPanel);
  }

  private static enum State
  {
    static
    {
      FLYING = new State("FLYING", 4);
      State[] arrayOfState = new State[5];
      arrayOfState[0] = ABOUT_TO_ANIMATE;
      arrayOfState[1] = ANIMATING;
      arrayOfState[2] = READY;
      arrayOfState[3] = TRACKING;
      arrayOfState[4] = FLYING;
      $VALUES = arrayOfState;
    }
  }
}

/* Location:           C:\Development\Android_Java_C\Workspace\TouchWizCalculator\TouchWizCalculator_dex2jar.jar
 * Qualified Name:     com.sec.android.widgetapp.calculator.Panel
 * JD-Core Version:    0.6.0
 */